<?php
class ClsSmarty extends Smarty2PHP
{
    //public $tplContent="";
    public $arrToken=array();
    public function __construct($tplContent) 
    {
        //$this->tplContent=$tplContent;
        parent::__construct($tplContent);
    }
    public function read()
    {
        $arrContent=splitByComment($this->tplContent,array('{*'));
        $arrF=array();
        for($i=0;$i<count($arrContent);$i++)
        {
            if($i%2===1) 
            {
                $arrF[]=array("type"=>"comment","content"=>$arrContent[$i]);
                continue;       
            }
            if(empty($arrContent[$i])) continue;
            $arrSplitContent=splitByTag($arrContent[$i],"literal","{","}");
            for($k=0;$k<count($arrSplitContent);$k++)
            {
                $tmpContent=$arrSplitContent[$k]["content"];
                if($k%2===1)
                {
                    $tmpContent=str_replace("{literal}", "", $tmpContent);
                    $tmpContent=str_replace("{/literal}", "", $tmpContent);
                    $arrF[]=array("type"=>"literal","content"=>$tmpContent);
                    continue;
                } 
                $arrTmp=array();
                preg_match_all("/{.[^{]*}/", $tmpContent, $arrTmp); 
                $arrTmp2=preg_split("/{.[^{]*}/", $tmpContent);

                $arrF[]=array("type"=>"text","content"=>$arrTmp2[0]);
                for($m=0;$m<count($arrTmp[0]);$m++)
                {
                    //$arrF[]=$this->convertSmartyToPHP($arrTmp[0][$m]);
                    $arrF[]=array("type"=>"tag","content"=>$arrTmp[0][$m]);
                    $arrF[]=array("type"=>"text","content"=>$arrTmp2[$m+1]);
                }
            }
        }
        $this->arrToken=$arrF;
    }
}
?>